package design.create_prototype;

import org.junit.Test;

/**
 * 原型模式
 */
public class DemoPrototype {
    @Test
    public void test() throws CloneNotSupportedException {
        User user = new User();
        user.setName("luobiao");
        user.setAge(29);
        User cloneUser=(User) user.clone();
        System.out.println(cloneUser);
    }

    public class User implements Cloneable{
        public String name;
        public Integer age;

        @Override
        protected Object clone() throws CloneNotSupportedException {
            return super.clone();
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "Userddd{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

}
